//
//  TableBgView.m
//  O2O-AccountManager
//
//  Created by 李良 on 16/4/26.
//  Copyright © 2016年 liliang. All rights reserved.
//

#import "DLTableBgView.h"
#import <DGGCommonSDK/DLThemeAdapter.h>

@interface DLTableBgView ()
//是否展示按钮
@property (nonatomic, assign) BOOL isShowBtn;
- (IBAction)didSelectRefreshAction:(UITapGestureRecognizer *)sender;
@end

@implementation DLTableBgView
+ (instancetype)loadNibWithImageName:(NSString *)imageName title:(NSString *)title isShowBtn:(BOOL)isShowBtn btnTitle:(NSString *)btnTitle content:(NSString *)content centerY:(CGFloat)centerY buttonColor:(UIColor *)buttonColor block:(void(^)(void))block{
    DLTableBgView * view = [[NSBundle mainBundle] loadNibNamed:kDLUIKitXIBName(@"DLTableBgView") owner:self options:nil][0];
    UIImage *image = IMAGE_NAME(imageName);
    if(!image){
        image = [UIImage imageNamed:kDLUIKitImageName(imageName)];
    }
    view.imageView.image = image;
    view.centerY.constant = centerY;
    view.label.text = title;
    view.button.hidden = !isShowBtn;
    view.isShowBtn = isShowBtn;
    view.label.adjustsFontSizeToFitWidth = YES;
    view.backgroundColor = [[DLThemeAdapter shareInstance] dynamicColor:DGG_RGB(255, 255, 255) darkColor:DGG_RGB(30, 30, 31)];
    view.label.textColor = [[DLThemeAdapter shareInstance] dynamicColor:DGG_RGB(255, 255, 255) darkColor:DGG_RGB(147, 152, 161)];
    if ([NSString isEmpty:content]) {
        view.contentLabel.hidden = YES;
    }else{
        view.contentLabel.text = content;
    }
    if (isShowBtn) {
        [view.button setTitle:btnTitle forState:(UIControlStateNormal)];
        if(buttonColor){
            view.button.backgroundColor = buttonColor;
        }
        [view.button addTarget:view action:@selector(buttonClick) forControlEvents:(UIControlEventTouchUpInside)];
    }
    if (block) {
        view.block = block;
    }
    return view;
}

+ (instancetype)loadNibWithImageName:(NSString *)imageName title:(NSString *)title isShowBtn:(BOOL)isShowBtn btnTitle:(NSString *)btnTitle content:(NSString *)content buttonColor:(UIColor *)buttonColor block:(void(^)(void))block{
    return [self loadNibWithImageName:imageName title:title isShowBtn:isShowBtn btnTitle:btnTitle content:content centerY:0 buttonColor:buttonColor block:block];
}
    
- (void)buttonClick{
    if (self.block) {
        self.block();
    }
}
- (IBAction)didSelectRefreshAction:(UITapGestureRecognizer *)sender {
    if (!self.isShowBtn) {
        if (self.block) {
            self.block();
        }
    }
}
    @end
